package com.cskaoyan.utils;

import com.cskaoyan.bean.vo.BaseRespVo;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**如果参数验证不合法，封装不合法的提示信息
 * @author 杨丰韶
 * @time 2021/7/3-15:36
 */
public class InvalidatedParamsUtil {

    public static BaseRespVo resErrorVo(BindingResult bindingResult){
        FieldError fieldError = bindingResult.getFieldError();
        String errorField = fieldError.getField();
        String message = fieldError.getDefaultMessage();
        Object rejectedValue = fieldError.getRejectedValue();
        return BaseRespVo.fail(errorField+"不合法,"+message+",而你提交的是"+rejectedValue);
    }
}
